package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.YyClass;
import com.ruoyi.system.service.IYyTeacherService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YyRoom;
import com.ruoyi.system.service.IYyRoomService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 宿舍Controller
 *
 * @author ruoyi
 * @date 2024-03-12
 */
@Controller
@RequestMapping("/system/room")
public class YyRoomController extends BaseController
{
    private String prefix = "system/room";

    @Autowired
    private IYyRoomService yyRoomService;

    @Autowired
    private IYyTeacherService yyTeacherService;

    @RequiresPermissions("system:room:view")
    @GetMapping()
    public String room()
    {
        return prefix + "/room";
    }


    /**
     * 查询宿舍列表全部
     */
    @PostMapping("/listAll")
    @ResponseBody
    public AjaxResult listAll()
    {
        List<YyRoom> list = yyRoomService.listAll();
        return AjaxResult.success(list);
    }

    /**
     * 查询宿舍列表
     */
    @RequiresPermissions("system:room:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YyRoom yyRoom)
    {
        startPage();
        List<YyRoom> list = yyRoomService.selectYyRoomList(yyRoom);
        return getDataTable(list);
    }

    /**
     * 导出宿舍列表
     */
    @RequiresPermissions("system:room:export")
    @Log(title = "宿舍", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YyRoom yyRoom)
    {
        List<YyRoom> list = yyRoomService.selectYyRoomList(yyRoom);
        ExcelUtil<YyRoom> util = new ExcelUtil<YyRoom>(YyRoom.class);
        return util.exportExcel(list, "宿舍数据");
    }

    /**
     * 新增宿舍
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        return prefix + "/add";
    }

    /**
     * 新增保存宿舍
     */
    @RequiresPermissions("system:room:add")
    @Log(title = "宿舍", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YyRoom yyRoom)
    {
        return toAjax(yyRoomService.insertYyRoom(yyRoom));
    }

    /**
     * 修改宿舍
     */
    @RequiresPermissions("system:room:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        YyRoom yyRoom = yyRoomService.selectYyRoomById(id);
        mmap.put("yyRoom", yyRoom);
        return prefix + "/edit";
    }

    /**
     * 修改保存宿舍
     */
    @RequiresPermissions("system:room:edit")
    @Log(title = "宿舍", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YyRoom yyRoom)
    {
        return toAjax(yyRoomService.updateYyRoom(yyRoom));
    }

    /**
     * 删除宿舍
     */
    @RequiresPermissions("system:room:remove")
    @Log(title = "宿舍", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(yyRoomService.deleteYyRoomByIds(ids));
    }
}
